/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package cn.knet.sp.ncrm.modules.office.notify.service;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.knet.sp.ncrm.common.persistence.Page;
import cn.knet.sp.ncrm.common.service.CrudService;
import cn.knet.sp.ncrm.modules.office.notify.entity.OfficeNotifyRecord;
import cn.knet.sp.ncrm.modules.office.notify.dao.OfficeNotifyRecordDao;
import cn.knet.sp.ncrm.modules.sys.user.entity.User;

/**
 * 系统通知、预约提醒记录Service
 * @author gehaiyang
 * @version 2015-07-20
 */
@Service
@Transactional(readOnly = true)
public class OfficeNotifyRecordService extends CrudService<OfficeNotifyRecordDao, OfficeNotifyRecord> {

	public OfficeNotifyRecord get(String id) {
		return super.get(id);
	}
	
	public List<OfficeNotifyRecord> findList(OfficeNotifyRecord officeNotifyRecord) {
		return super.findList(officeNotifyRecord);
	}
	
	public Page<OfficeNotifyRecord> findPage(Page<OfficeNotifyRecord> page, OfficeNotifyRecord officeNotifyRecord) {
		return super.findPage(page, officeNotifyRecord);
	}
	
	@Transactional(readOnly = false)
	public void save(OfficeNotifyRecord officeNotifyRecord) {
		super.save(officeNotifyRecord);
	}
	
	@Transactional(readOnly = false)
	public void delete(OfficeNotifyRecord officeNotifyRecord) {
		super.delete(officeNotifyRecord);
	}
	
	/**
	 *  TODO(标记已读)
	 * @author Gehaiyang
	 * @date 2015年7月22日 下午2:00:36
	 * @param officeNotifyRecord
	 */
	public void read(OfficeNotifyRecord officeNotifyRecord){
		officeNotifyRecord.setReadFlag("1");
		officeNotifyRecord.setReadDate(new Date());
		super.save(officeNotifyRecord);
	}
	
	public int getUnreadCount(User user){
		OfficeNotifyRecord officeNotifyRecord = new OfficeNotifyRecord();
    	officeNotifyRecord.setUser(user);
    	return dao.findUnreadCount(officeNotifyRecord);
	}
}